<template>
  <div class="stock-details">
    <a-spin :spinning="loading">
      <a-form :model="formState" autocomplete="off">
        <div class="base-info">
          <div class="title">基础信息</div>
          <a-row :gutter="8">
            <a-col v-for="(item, index) in formItemColumn" :key="index" :span="8">
              <a-form-item
                :class="[['waybillNum', 'pickupCity', 'addressType'].includes(item.name) ? 'emphasis-item' : '']"
                v-bind="item"
                :label-col="{ style: 'width:110px' }"
                :wrapper-col="{ style: 'calc(100% - 110px)' }"
              >
                <template v-if="item.name === 'addressType'">
                  {{ getLabelByDict("WAYBILL_TYPE", formState[item.name]) }}
                </template>
                <template v-else-if="item.name === 'customsDeclarationTitle'">
                  {{ formState[item.name] }}
                </template>
                <template v-else-if="item.name === 'countryRegionName'">
                  <span>{{ formState[item.name] }} </span>
                  <a-button type="link" @click="modifyCountryRegionNameHandle">修改</a-button>
                </template>
                <template v-else-if="item.name === 'itemNumber'">
                  {{ formState[item.name] }}
                  <a-button type="link" @click="modifyItemNumbereHandle">修改</a-button>
                </template>
                <template v-else-if="item.name === 'makeInvoiceStatus'">
                  <a-button type="link" @click="showInvoiceHandle">查看发票</a-button>
                  <a-button v-if="passData.makeInvoiceStatus === -2" type="link" @click="modifyInvoiceHandle">修改发票</a-button>
                </template>
                <template v-else-if="item.name === 'shippingMethod'">
                  <span v-if="formState.shippingMethod === 0">上门取件</span>
                  <span v-if="formState.shippingMethod === 1">自送入仓</span>
                </template>
                <template v-else>{{ formState[item.name] }}</template>
              </a-form-item>
            </a-col>
          </a-row>
        </div>
      </a-form>

      <div class="box-info">
        <div class="title">
          <div style="display: flex">
            <span>材积明细</span>
            <div style="margin-left: 10px">
              客户可见:
              <a-switch v-model:checked="formState.customerPicimgShow" checked-children="开" un-checked-children="关" @click="isShowPhotoHandle" />
            </div>
          </div>
          <span>总结算重: {{ formState.settlementWeight || 0 }}</span>
        </div>
        <div class="table-content">
          <vxe-table border show-overflow="title" height="600" size="small" :row-config="{ height: 45 }" :data="formState.preOrderShipmentBoxVolume" :scroll-y="{ enabled: true, gt: 30 }">
            <vxe-column type="seq" width="50"></vxe-column>
            <vxe-column field="shipmentBoxNumber" title="系统箱号" min-width="140">
              <template #default="{ row }">
                <div>{{ row.fbaBoxNumber }}</div>
                <div>{{ row.shipmentBoxNumber }}</div>
              </template>
            </vxe-column>
            <vxe-column field="pickingBoxLength" title="长"></vxe-column>
            <vxe-column field="pickingBoxWidth" title="宽"></vxe-column>
            <vxe-column field="pickingBoxHeight" title="高"></vxe-column>
            <vxe-column field="pickingBoxWeight" title="实重"></vxe-column>
            <vxe-column field="volumeWeight" title="材积重"></vxe-column>
            <vxe-column field="circumference" title="周长"></vxe-column>
            <vxe-column field="picture" title="拣货图片" min-width="100">
              <template #default="{ row }">
                <a-image v-if="row.picture" :width="50" :src="row.picture" />
              </template>
            </vxe-column>
          </vxe-table>
        </div>
      </div>

      <div class="file-list">
        <div class="title">
          <span>附件</span>
          <a-button type="primary" @click="uploadFileHandle">上传附件</a-button>
        </div>
        <div class="table-content">
          <vxe-table border show-overflow="title" height="95%" :data="formState.bizPreOrderShipmentFileResDtoList" :scroll-y="{ enabled: true, gt: 30 }">
            <vxe-column field="filename" title="文件名" min-width="140"></vxe-column>
            <vxe-column field="createName" title="上传人"></vxe-column>
            <vxe-column field="fileType" title="类型">
              <template #default="{ row }">
                <span v-if="row.fileType * 1 === 2">其他</span>
                <span v-if="row.fileType * 1 === 1">报关单</span>
              </template>
            </vxe-column>
            <vxe-column field="createTime" title="上传时间">
              <template #default="{ row }">
                {{ dayjs(Number(row.createTime)).format("YYYY-MM-DD HH:mm:ss") }}
              </template>
            </vxe-column>
            <vxe-column field="customerShow" title="客户可见">
              <template #default="{ row }">
                <a-switch v-model:checked="row.customerShow" @change="(e:boolean)=> changeStatus(e,row)" :loading="loading" />
              </template>
            </vxe-column>
            <vxe-column field="action" title="操作">
              <template #default="{ row }">
                <a-button type="link" @click="downloadFileHandle(row)">下载附件</a-button>
                <a-button type="link" danger @click="deleteFileHandle(row)">删除</a-button>
              </template>
            </vxe-column>
          </vxe-table>
        </div>
      </div>
    </a-spin>
    <a-modal v-model:visible="dialogOpts.visible" :maskClosable="false" :keyboard="false" :closable="false" :footer="null" :title="dialogOpts.title" :width="dialogOpts.width">
      <component v-model:visible="dialogOpts.visible" :is="dialogOpts.component" :type="dialogOpts.type" :pass-data="dialogOpts.passData" @submit="dialogSubmitHandle"></component>
    </a-modal>
    <!-- 抽屉 -->
    <a-drawer class="custom-drawer" v-model:visible="drawerOpts.visible" :title="drawerOpts.title" :maskClosable="false" :closable="true" :width="drawerOpts.width" placement="right">
      <component v-model:visible="drawerOpts.visible" :is="drawerOpts.component" :type="drawerOpts.type" :pass-data="drawerOpts.passData" @submit="drawerSubmitHandle"></component>
    </a-drawer>
  </div>
</template>
<script lang="ts">
import UploadFile from "../uploadFile/index.vue";
import ShowInvoice from "../showInvoice/index.vue";
import MakeInvoice from "../makeInvoice/index.vue";
import ModifyCount from "../modifyCount/index.vue";
import ModifyCountryRegionName from "@/views/waybillManagement/customerServiceWaybill/components/modifyCountryRegionName/index.vue";

export default {
  components: {
    UploadFile,
    ShowInvoice,
    MakeInvoice,
    ModifyCount,
    ModifyCountryRegionName
  }
};
</script>
<script lang="ts" setup>
import dayjs from "dayjs";
import { formItemColumn } from "./data";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import CommonHook from "@/hook/commonHook";
import ModalHook from "@/hook/modalHook";
import { toRefs, watch } from "vue";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    type: number;
    passData: StockManagement.ListRows;
  }>(),
  {}
);
const { visible, passData } = toRefs(props);
const { getLabelByDict, downloadFileByUrl } = CommonHook();
const { formState, loading, dialogOpts, init, drawerOpts } = InitHook();
const { deleteFileHandle, downloadFileHandle, uploadFileHandle, showInvoiceHandle, modifyInvoiceHandle, modifyItemNumbereHandle, modifyCountryRegionNameHandle, isShowPhotoHandle, changeStatus } =
  OperationHook({
    dialogOpts,
    formState,
    passData,
    downloadFileByUrl,
    init,
    drawerOpts,
    loading
  });
const { dialogSubmitHandle, drawerSubmitHandle } = ModalHook({
  dialogOpts,
  drawerOpts,
  callBack: () => init(passData.value.id)
});
watch(
  () => visible.value,
  (v: boolean) => {
    if (v) init(passData.value.id);
  }
);
init(passData.value.id);
</script>
<style lang="stylus" scoped>
.stock-details {
    .title{
        font-weight: 600;
        font-size: 14px;
        padding: 12px;
    }
    .base-info{
        background-color: #fff;
        border-radius: 8px;
        box-shadow: 0px 0px 4px 0px #ccc;
        font-weight: 600;
        .emphasis-item {
          color: #fe8100;
          > :deep(.ant-form-item-label){
            >label{
              color: #fe8100;
            }
          }
        }
        :deep(.ant-form-item){
          margin-bottom: 8px;
        }
    }
    .box-info{
      margin-top: 12px;
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0px 0px 4px 0px #ccc;
      font-weight: 600;
      .title{
          display: flex;
          justify-content: space-between;
          align-items: center;
      }
      .table-content{
        padding: 0 12px 12px 12px;
      }
  }
    .file-list{
      margin-top: 12px;
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0px 0px 4px 0px #ccc;
      font-weight: 600;
      .title{
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .table-content{
        padding: 0 12px 12px 12px;
        height: calc(100vh - 570px);
      }
    }
}
</style>
